//
//  GYGoods.m
//  GoodLuck
//
//  Created by apple on 2018/2/27.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYGoods.h"

@implementation GYGoods

+ (NSArray *)loadGoods:(NSArray *)source {
    NSMutableArray *goods = [NSMutableArray array];
    
    for (NSDictionary *dic in source) {
        GYGoods *good = [[GYGoods alloc] initWithDic:dic];
        [goods addObject:good];
    }
    
    return goods;
}

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    NSLog(@"key =====%@",key);
}

- (NSString *)description {
    NSArray *keys = @[@"goods_id",@"goods_name",@"goods_promotion_price",@"goods_image"];
    
    return [NSString stringWithFormat:@"%@",[self dictionaryWithValuesForKeys:keys]];
}

- (CGFloat)getHeight {
    CGFloat height = 0;
    //1.添加图片的高度
    height += (ScreenWidth-30)/2;
    
    //2.添加描述的高度
//    CGSize desSize = [self.goods_name boundingRectWithSize:CGSizeMake((ScreenWidth-30)/2-2, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size;
    height += 50;//desSize.height;
    
    CGSize pirceSize = [self.goods_promotion_price boundingRectWithSize:CGSizeMake((ScreenWidth-30)/2-2, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size;
    
    height += pirceSize.height + 30;
    
    return height;
}

@end
